home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / sh.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-16  |  23.7 KB  |  838 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/sh.h,v 3.11 1991/08/05 23:02:13 christos Exp $ */
  2. /*
  3.  * sh.h: Catch it all globals and includes file!
  4.  */
  5. /*-
  6.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Berkeley and its contributors.
  21.  * 4. Neither the name of the University nor the names of its contributors
  22.  *    may be used to endorse or promote products derived from this software
  23.  *    without specific prior written permission.
  24.  *
  25.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35.  * SUCH DAMAGE.
  36.  */
  37. #ifndef _h_sh
  38. #define _h_sh
  39.  
  40.  
  41. /*
  42.  * Sanity
  43.  */
  44. #if defined(_POSIX_SOURCE) && !defined(POSIX)
  45. # define POSIX
  46. #endif 
  47.  
  48. #if defined(POSIXJOBS) && !defined(BSDJOBS)
  49. # define BSDJOBS
  50. #endif 
  51.  
  52. #ifdef SHORT_STRINGS
  53. typedef short Char;
  54. # define SAVE(a) (Strsave(str2short(a)))
  55. #else
  56. typedef char Char;
  57. # define SAVE(a) (strsave(a))
  58. #endif 
  59.  
  60. /*
  61.  * If your compiler complains, then you can either
  62.  * throw it away and get gcc or, use the following define
  63.  * and get rid of the typedef.
  64.  * [The 4.2/3BSD vax compiler does not like that]
  65.  */
  66. #ifdef SIGVOID
  67. # if (defined(vax) || defined(uts)) && !defined(__GNUC__)
  68. #  define sigret_t void
  69. # else
  70. typedef void sigret_t;
  71. # endif 
  72. #else
  73. typedef int sigret_t;
  74. #endif /* SIGVOID */
  75.  
  76.  
  77. /*
  78.  * Fundamental definitions which may vary from system to system.
  79.  *
  80.  *    BUFSIZ        The i/o buffering size; also limits word size
  81.  *    MAILINTVL    How often to mailcheck; more often is more expensive
  82.  */
  83. #ifndef BUFSIZ
  84. #define    BUFSIZ    1024        /* default buffer size */
  85. #endif /* BUFSIZ */
  86.  
  87. #define FORKSLEEP    10    /* delay loop on non-interactive fork failure */
  88. #define    MAILINTVL    600    /* 10 minutes */
  89.  
  90. /*
  91.  * The shell moves std in/out/diag and the old std input away from units
  92.  * 0, 1, and 2 so that it is easy to set up these standards for invoked
  93.  * commands.
  94.  */
  95. #define    FSHTTY    15        /* /dev/tty when manip pgrps */
  96. #define    FSHIN    16        /* Preferred desc for shell input */
  97. #define    FSHOUT    17        /* ... shell output */
  98. #define    FSHDIAG    18        /* ... shell diagnostics */
  99. #define    FOLDSTD    19        /* ... old std input */
  100.  
  101. #ifdef PROF
  102. #define    xexit(n)    done(n)
  103. #endif 
  104.  
  105. #include <sys/types.h>
  106. #ifdef _SEQUENT_
  107. # include <sys/procstats.h>
  108. #endif /* _SEQUENT_ */
  109. #if defined(POSIX) || SVID > 0 || defined(__MINT__)
  110. # include <sys/times.h>
  111. #endif /* POSIX || SVID > 0 */
  112.  
  113. #ifdef NLS
  114. # include <locale.h>
  115. #endif 
  116.  
  117. #include <sys/param.h>
  118. #include <sys/stat.h>
  119.  
  120. #ifdef BSDTIMES
  121. # include <sys/time.h>
  122. # include <sys/resource.h>
  123. #endif /* BSDTIMES */
  124.  
  125. #ifndef POSIX
  126. # ifdef TERMIO
  127. #  ifdef _IBMR2
  128.  /* Aix redefines NOFLSH when _BSD_INCLUDES is defined! */
  129. #   undef _BSD
  130. #   undef _BSD_INCLUDES
  131. #  endif /* _IBMR2 */
  132. #  include <termio.h>
  133. #  ifdef _IBMR2
  134.  /* but we need it.  */
  135. #   define _BSD
  136. #   define _BSD_INCLUDES
  137. #  endif /* _IBMR2 */
  138. # else
  139. #  include <sgtty.h>
  140. # endif /* TERMIO */
  141. #else                /* POSIX */
  142. # include <termios.h>
  143. #endif /* POSIX */
  144.  
  145. #if defined(POSIX) || defined(__MINT__)
  146. /*
  147.  * We should be using setpgid and setpgid
  148.  * by now, but in some systems we use the
  149.  * old routines...
  150.  */
  151. # define getpgrp __getpgrp
  152. # define setpgrp __setpgrp
  153. # include <unistd.h>
  154. # undef getpgrp
  155. # undef setpgrp
  156. extern int getpgrp();
  157. extern int setpgrp();
  158.  
  159. /*
  160.  * the gcc+protoize version of <stdlib.h>
  161.  * redefines malloc(), so we define the following
  162.  * to avoid it.
  163.  */
  164. # define _GNU_STDLIB_H
  165. # define malloc __malloc
  166. # define free __free
  167. # define calloc __calloc
  168. # define realloc __realloc
  169. # include <stdlib.h>
  170. # undef malloc
  171. # undef free
  172. # undef calloc
  173. # undef realloc
  174. # include <limits.h>
  175. #endif /* POSIX */
  176.  
  177. #if SVID > 0
  178. # if !defined(pyr) || !defined(aiws)
  179. #  include <time.h>
  180. # endif /* !aiws || !pyr */
  181. #endif /* SVID > 0 */
  182.  
  183. #if !(defined(sun) && defined(TERMIO))
  184. # include <sys/ioctl.h>
  185. #endif 
  186.  
  187. #if !defined(FIOCLEX) && defined(sun)
  188. # include <sys/filio.h>
  189. #endif /* !FIOCLEX && sun */
  190.  
  191.  
  192. #include <sys/file.h>
  193.  
  194. #if !defined(O_RDONLY) || !defined(O_NDELAY)
  195. # include <fcntl.h>
  196. #endif 
  197.  
  198. #include <errno.h>
  199.  
  200. #include <setjmp.h>
  201.  
  202. #if __STDC__
  203. # include <stdarg.h>
  204. #else
  205. # include <varargs.h>
  206. #endif 
  207.  
  208. #ifdef DIRENT
  209. # include <dirent.h>
  210. #else
  211. # ifdef hp9000s500
  212. #  include <ndir.h>
  213. # else
  214. #  include <sys/dir.h>
  215. # endif
  216. # define dirent direct
  217. #endif /* DIRENT */
  218. #ifdef hpux
  219. # include <stdio.h>    /* So the fgetpwent() prototypes work */
  220. #endif 
  221. #include <pwd.h>
  222. #ifdef BSD
  223. # include <strings.h>
  224. # define strchr(a, b) index(a, b)
  225. # define strrchr(a, b) rindex(a, b)
  226. #else
  227. # include <string.h>
  228. #endif /* BSD */
  229.  
  230.  
  231. /*
  232.  * ANSIisms... These must be *after* the system include and 
  233.  * *before* our includes, so that BSDreno has time to define __P
  234.  */
  235. #ifndef __P
  236. # if __STDC__
  237. #  define __P(a) a
  238. # else
  239. #  define __P(a) ()
  240. #  define const
  241. #  ifndef apollo
  242. #   define volatile    /* Apollo 'c' extensions need this */
  243. #  endif /* apollo */
  244. # endif 
  245. #endif 
  246.  
  247.  
  248. #ifdef __MINT__
  249. #define is_dirsep(c) ((c) == '/' || (c) == '\\')
  250. #define is_abspath(p) (is_dirsep(*p) || (p[1] == ':'))
  251. #endif
  252.  
  253. typedef int bool;
  254.  
  255. #include "sh.types.h"
  256.  
  257. #ifndef lint
  258. typedef ptr_t memalign_t;
  259. #else
  260. typedef union {
  261.     char    am_char, *am_char_p;
  262.     short   am_short, *am_short_p;
  263.     int     am_int, *am_int_p;
  264.     long    am_long, *am_long_p;
  265.     float   am_float, *am_float_p;
  266.     double  am_double, *am_double_p;
  267. }      *memalign_t;
  268.  
  269. # define malloc        lint_malloc
  270. # define free        lint_free
  271. # define realloc    lint_realloc
  272. # define calloc        lint_calloc
  273. #endif 
  274.  
  275. #ifdef SYSMALLOC
  276. # define xmalloc(i)      Malloc(i)
  277. # define xrealloc(p, i)    Realloc(p, i)
  278. # define xcalloc(n, s)    Calloc(n, s)
  279. # define xfree(p)        Free(p)
  280. #else
  281. # define xmalloc(i)      malloc(i)
  282. # define xrealloc(p, i)    realloc(p, i)
  283. # define xcalloc(n, s)    calloc(n, s)
  284. # define xfree(p)        free(p)
  285. #endif /* SYSMALLOC */
  286. #include "sh.char.h"
  287. #include "sh.err.h"
  288. #include "sh.dir.h"
  289. #include "sh.proc.h"
  290.  
  291. #include "pathnames.h"
  292.  
  293.  
  294. /*
  295.  * C shell
  296.  *
  297.  * Bill Joy, UC Berkeley
  298.  * October, 1978; May 1980
  299.  *
  300.  * Jim Kulp, IIASA, Laxenburg Austria
  301.  * April, 1980
  302.  */
  303.  
  304. #define SIGN_EXTEND_CHAR(a) \
  305.     ((a) & 0x80 ? ((int) (a)) | 0xffffff00 : ((int) a) & 0x000000ff)
  306.  
  307.  
  308.  
  309. #if !defined(MAXNAMLEN) && defined(_D_NAME_MAX)
  310. # define MAXNAMLEN _D_NAME_MAX
  311. #endif /* MAXNAMLEN */
  312.  
  313. #ifndef MAXHOSTNAMELEN
  314. # define MAXHOSTNAMELEN    255
  315. #endif /* MAXHOSTNAMELEN */
  316.  
  317.  
  318.  
  319. #define    eq(a, b)    (Strcmp(a, b) == 0)
  320.  
  321. /* globone() flags */
  322. #define G_ERROR        0    /* default action: error if multiple words */
  323. #define G_IGNORE    1    /* ignore the rest of the words           */
  324. #define G_APPEND    2    /* make a sentence by cat'ing the words    */
  325.  
  326. /*
  327.  * Global flags
  328.  */
  329. bool    chkstop;        /* Warned of stopped jobs... allow exit */
  330.  
  331. #ifndef FIOCLEX
  332. bool    didcch;            /* Have closed unused fd's for child */
  333. #endif 
  334.  
  335. bool    didfds;            /* Have setup i/o fd's for child */
  336. bool    doneinp;        /* EOF indicator after reset from readc */
  337. bool    exiterr;        /* Exit if error or non-zero exit status */
  338. bool    child;            /* Child shell ... errors cause exit */
  339. bool    haderr;            /* Reset was because of an error */
  340. bool    intty;            /* Input is a tty */
  341. bool    intact;            /* We are interactive... therefore prompt */
  342. bool    justpr;            /* Just print because of :p hist mod */
  343. bool    loginsh;        /* We are a loginsh -> .login/.logout */
  344. bool    neednote;        /* Need to pnotify() */
  345. bool    noexec;            /* Don't execute, just syntax check */
  346. bool    pjobs;            /* want to print jobs if interrupted */
  347. bool    setintr;        /* Set interrupts on/off -> Wait intr... */
  348. bool    timflg;            /* Time the next waited for command */
  349. bool    havhash;        /* path hashing is available */
  350. bool    editing;        /* doing filename expansion and line editing */
  351. bool    bslash_quote;        /* PWP: tcsh-style quoting?  (in sh.c) */
  352. bool    isoutatty;        /* is SHOUT a tty */
  353. bool    isdiagatty;        /* is SHDIAG a tty */
  354. bool    is1atty;        /* is file descriptor 1 a tty (didfds mode) */
  355. bool    is2atty;        /* is file descriptor 2 a tty (didfds mode) */
  356.  
  357. /*
  358.  * Global i/o info
  359.  */
  360. Char   *arginp;            /* Argument input for sh -c and internal `xx` */
  361. int     onelflg;        /* 2 -> need line for -t, 1 -> exit on read */
  362. Char   *ffile;            /* Name of shell file for $0 */
  363.  
  364. extern char *seterr;        /* Error message from scanner/parser */
  365. extern int errno;        /* Error from C library routines */
  366. Char   *shtemp;            /* Temp name for << shell files in /tmp */
  367.  
  368. #ifdef BSDTIMES
  369. struct timeval time0;        /* Time at which the shell started */
  370. struct rusage ru0;
  371. #else
  372. # ifdef _SEQUENT_
  373. timeval_t time0;        /* Time at which the shell started */
  374. struct process_stats ru0;
  375. # else                /* _SEQUENT_ */
  376. #  ifndef POSIX
  377. time_t  time0;            /* time at which shell started */
  378. #  else                /* POSIX */
  379. clock_t time0;            /* time at which shell started */
  380. #  endif /* POSIX */
  381. struct tms shtimes;        /* shell and child times for process timing */
  382. # endif /* _SEQUENT_ */
  383. #endif /* BSDTIMES */
  384.  
  385. /*
  386.  * Miscellany
  387.  */
  388. Char   *doldol;            /* Character pid for $$ */
  389. time_t  chktim;            /* Time mail last checked */
  390.  
  391. /*
  392.  * Ideally these should be uid_t, gid_t, pid_t. I cannot do that right now
  393.  * cause pid's could be unsigned and that would break our -1 flag, and 
  394.  * uid_t and gid_t are not defined in all the systems so I would have to
  395.  * make special cases for them. In the future...
  396.  */
  397. int     uid;            /* Invokers uid */
  398. int     gid;            /* Invokers gid */
  399. int     opgrp,            /* Initial pgrp and tty pgrp */
  400.         shpgrp,            /* Pgrp of shell */
  401.         tpgrp;            /* Terminal process group */
  402.                 /* If tpgrp is -1, leave tty alone! */
  403.  
  404. Char    PromptBuf[256];        /* buffer for the actual printed prompt. this
  405.                  * is used in tenex.c and sh.c for pegets.c */
  406.  
  407. /*
  408.  * To be able to redirect i/o for builtins easily, the shell moves the i/o
  409.  * descriptors it uses away from 0,1,2.
  410.  * Ideally these should be in units which are closed across exec's
  411.  * (this saves work) but for version 6, this is not usually possible.
  412.  * The desired initial values for these descriptors are defined in
  413.  * sh.local.h.
  414.  */
  415. int   SHIN;            /* Current shell input (script) */
  416. int   SHOUT;            /* Shell output */
  417. int   SHDIAG;            /* Diagnostic output... shell errs go here */
  418. int   OLDSTD;            /* Old standard input (def for cmds) */
  419.  
  420. /*
  421.  * Error control
  422.  *
  423.  * Errors in scanning and parsing set up an error message to be printed
  424.  * at the end and complete.  Other errors always cause a reset.
  425.  * Because of source commands and .cshrc we need nested error catches.
  426.  */
  427.  
  428. extern jmp_buf reslab;
  429.  
  430. /* bugfix by Jak Kirman @ Brown U.: remove the (void) cast here, see sh.c */
  431. #define    setexit()    (setjmp(reslab))
  432. #define    reset()        longjmp(reslab, 1)
  433.  /* Should use structure assignment here */
  434. #define    getexit(a)    copy((char *)(a), (char *)reslab, sizeof reslab)
  435. #define    resexit(a)    copy((char *)reslab, ((char *)(a)), sizeof reslab)
  436.  
  437. Char   *gointr;            /* Label for an onintr transfer */
  438.  
  439. sigret_t (*parintr) ();        /* Parents interrupt catch */
  440. sigret_t (*parterm) ();        /* Parents terminate catch */
  441.  
  442. #ifdef ALTESC
  443. Char escchar;    /* character that should be used instead of \ for quoting */
  444. #else
  445. #define escchar '\\'
  446. #endif
  447.  
  448. /*
  449.  * Lexical definitions.
  450.  *
  451.  * All lexical space is allocated dynamically.
  452.  * The eighth/sixteenth bit of characters is used to prevent recognition,
  453.  * and eventually stripped.
  454.  */
  455. #define        META        0200
  456. #define        ASCII        0177
  457. #ifdef SHORT_STRINGS
  458. # define    QUOTE         0100000    /* 16nth char bit used for 'ing */
  459. # define    TRIM        0077777    /* Mask to strip quote bit */
  460. # define    UNDER        0040000    /* Underline flag */
  461. # define    BOLD        0020000    /* Bold flag */
  462. # define    STANDOUT    0010000    /* Standout flag */
  463. # define    LITERAL        0004000    /* Literal character flag */
  464. # define    ATTRIBUTES    0074000    /* The bits used for attributes */
  465. # define    CHAR        0000377    /* Mask to mask out the character */
  466. #else
  467. # define    QUOTE         0200    /* Eighth char bit used for 'ing */
  468. # define    TRIM        0177    /* Mask to strip quote bit */
  469. # define    UNDER        0000000    /* No extra bits to do both */
  470. # define    BOLD        0000000    /* Bold flag */
  471. # define    STANDOUT    META    /* Standout flag */
  472. # define    LITERAL        0000000    /* Literal character flag */
  473. # define    ATTRIBUTES    0200    /* The bits used for attributes */
  474. # define    CHAR        0000177    /* Mask to mask out the character */
  475. #endif 
  476.  
  477. int     AsciiOnly;        /* If set only 7 bits is expected in characters */
  478.  
  479. /*
  480.  * Each level of input has a buffered input structure.
  481.  * There are one or more blocks of buffered input for each level,
  482.  * exactly one if the input is seekable and tell is available.
  483.  * In other cases, the shell buffers enough blocks to keep all loops
  484.  * in the buffer.
  485.  */
  486. struct Bin {
  487.     off_t   Bfseekp;        /* Seek pointer */
  488.     off_t   Bfbobp;        /* Seekp of beginning of buffers */
  489.     off_t   Bfeobp;        /* Seekp of end of buffers */
  490.     int     Bfblocks;        /* Number of buffer blocks */
  491.     Char  **Bfbuf;        /* The array of buffer blocks */
  492. }       B;
  493.  
  494. #define    fseekp    B.Bfseekp
  495. #define    fbobp    B.Bfbobp
  496. #define    feobp    B.Bfeobp
  497. #define    fblocks    B.Bfblocks
  498. #define    fbuf    B.Bfbuf
  499.  
  500. #define btell()    fseekp
  501.  
  502. /*
  503.  * The shell finds commands in loops by reseeking the input
  504.  * For whiles, in particular, it reseeks to the beginning of the
  505.  * line the while was on; hence the while placement restrictions.
  506.  */
  507. off_t   lineloc;
  508.  
  509. bool    cantell;        /* Is current source tellable ? */
  510.  
  511. /*
  512.  * Input lines are parsed into doubly linked circular
  513.  * lists of words of the following form.
  514.  */
  515. struct wordent {
  516.     Char   *word;
  517.     struct wordent *prev;
  518.     struct wordent *next;
  519. };
  520.  
  521. /*
  522.  * During word building, both in the initial lexical phase and
  523.  * when expanding $ variable substitutions, expansion by `!' and `$'
  524.  * must be inhibited when reading ahead in routines which are themselves
  525.  * processing `!' and `$' expansion or after characters such as `\' or in
  526.  * quotations.  The following flags are passed to the getC routines
  527.  * telling them which of these substitutions are appropriate for the
  528.  * next character to be returned.
  529.  */
  530. #define    DODOL    1
  531. #define    DOEXCL    2
  532. #define    DOALL    DODOL|DOEXCL
  533.  
  534. /*
  535.  * Labuf implements a general buffer for lookahead during lexical operations.
  536.  * Text which is to be placed in the input stream can be stuck here.
  537.  * We stick parsed ahead $ constructs during initial input,
  538.  * process id's from `$$', and modified variable values (from qualifiers
  539.  * during expansion in sh.dol.c) here.
  540.  */
  541. Char   *lap;
  542.  
  543. /*
  544.  * Parser structure
  545.  *
  546.  * Each command is parsed to a tree of command structures and
  547.  * flags are set bottom up during this process, to be propagated down
  548.  * as needed during the semantics/exeuction pass (sh.sem.c).
  549.  */
  550. struct command {
  551.     short   t_dtyp;        /* Type of node          */
  552. #define    NODE_COMMAND    1    /* t_dcom <t_dlef >t_drit     */
  553. #define    NODE_PAREN    2    /* ( t_dspr ) <t_dlef >t_drit     */
  554. #define    NODE_PIPE    3    /* t_dlef | t_drit         */
  555. #define    NODE_LIST    4    /* t_dlef ; t_drit         */
  556. #define    NODE_OR        5    /* t_dlef || t_drit         */
  557. #define    NODE_AND    6    /* t_dlef && t_drit         */
  558.     short   t_dflg;        /* Flags, e.g. F_AMPERSAND|...      */
  559. /* save these when re-doing      */
  560. #ifndef apollo
  561. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP)    
  562. #else
  563. #define    F_SAVE    (F_NICE|F_TIME|F_NOHUP|F_VER)
  564. #endif 
  565. #define    F_AMPERSAND    (1<<0)    /* executes in background     */
  566. #define    F_APPEND    (1<<1)    /* output is redirected >>     */
  567. #define    F_PIPEIN    (1<<2)    /* input is a pipe         */
  568. #define    F_PIPEOUT    (1<<3)    /* output is a pipe         */
  569. #define    F_NOFORK    (1<<4)    /* don't fork, last ()ized cmd     */
  570. #define    F_NOINTERRUPT    (1<<5)    /* should be immune from intr's */
  571. /* spare */
  572. #define    F_STDERR    (1<<7)    /* redirect unit 2 with unit 1     */
  573. #define    F_OVERWRITE    (1<<8)    /* output was !             */
  574. #define    F_READ        (1<<9)    /* input redirection is <<     */
  575. #define    F_REPEAT    (1<<10)    /* reexec aft if, repeat,...     */
  576. #define    F_NICE        (1<<11)    /* t_nice is meaningful      */
  577. #define    F_NOHUP        (1<<12)    /* nohup this command          */
  578. #define    F_TIME        (1<<13)    /* time this command          */
  579. #ifdef apollo
  580. #define F_VER        (1<<14)    /* execute command under SYSTYPE */
  581. #endif 
  582.     union {
  583.     Char   *T_dlef;        /* Input redirect word          */
  584.     struct command *T_dcar;    /* Left part of list/pipe      */
  585.     }       L;
  586.     union {
  587.     Char   *T_drit;        /* Output redirect word      */
  588.     struct command *T_dcdr;    /* Right part of list/pipe      */
  589.     }       R;
  590. #define    t_dlef    L.T_dlef
  591. #define    t_dcar    L.T_dcar
  592. #define    t_drit    R.T_drit
  593. #define    t_dcdr    R.T_dcdr
  594.     Char  **t_dcom;        /* Command/argument vector      */
  595.     struct command *t_dspr;    /* Pointer to ()'d subtree      */
  596.     short   t_nice;
  597. #ifdef F_VER
  598.     short   t_systype;
  599. #endif 
  600. };
  601.  
  602.  
  603. /*
  604.  * The keywords for the parser
  605.  */
  606. #define    T_BREAK        0
  607. #define    T_BRKSW        1
  608. #define    T_CASE        2
  609. #define    T_DEFAULT     3
  610. #define    T_ELSE        4
  611. #define    T_END        5
  612. #define    T_ENDIF        6
  613. #define    T_ENDSW        7
  614. #define    T_EXIT        8
  615. #define    T_FOREACH    9
  616. #define    T_GOTO        10
  617. #define    T_IF        11
  618. #define    T_LABEL        12
  619. #define    T_LET        13
  620. #define    T_SET        14
  621. #define    T_SWITCH    15
  622. #define    T_TEST        16
  623. #define    T_THEN        17
  624. #define    T_WHILE        18
  625.  
  626. /*
  627.  * These are declared here because they want to be
  628.  * initialized in sh.init.c (to allow them to be made readonly)
  629.  */
  630.  
  631. extern struct biltins {
  632.     char   *bname;
  633.     void    (*bfunct) __P((Char **, struct command *));
  634.     int     minargs, maxargs;
  635. }       bfunc[];
  636. extern int nbfunc;
  637.  
  638. extern struct srch {
  639.     char   *s_name;
  640.     int     s_value;
  641. }       srchn[];
  642. extern int nsrchn;
  643.  
  644. /*
  645.  * Structure defining the existing while/foreach loops at this
  646.  * source level.  Loops are implemented by seeking back in the
  647.  * input.  For foreach (fe), the word list is attached here.
  648.  */
  649. struct whyle {
  650.     off_t   w_start;        /* Point to restart loop */
  651.     off_t   w_end;        /* End of loop (0 if unknown) */
  652.     Char  **w_fe, **w_fe0;    /* Current/initial wordlist for fe */
  653.     Char   *w_fename;        /* Name for fe */
  654.     struct whyle *w_next;    /* Next (more outer) loop */
  655. }      *whyles;
  656.  
  657. /*
  658.  * Variable structure
  659.  *
  660.  * Aliases and variables are stored in AVL balanced binary trees.
  661.  */
  662. struct varent {
  663.     Char  **vec;        /* Array of words which is the value */
  664.     Char   *v_name;        /* Name of variable/alias */
  665.     struct varent *v_link[3];    /* The links, see below */
  666.     int     v_bal;        /* Balance factor */
  667. }       shvhed, aliases;
  668.  
  669. #define v_left        v_link[0]
  670. #define v_right        v_link[1]
  671. #define v_parent    v_link[2]
  672.  
  673. struct varent *adrof1();
  674.  
  675. #define adrof(v)    adrof1(v, &shvhed)
  676. #define value(v)    value1(v, &shvhed)
  677.  
  678. /*
  679.  * The following are for interfacing redo substitution in
  680.  * aliases to the lexical routines.
  681.  */
  682. struct wordent *alhistp;    /* Argument list (first) */
  683. struct wordent *alhistt;    /* Node after last in arg list */
  684. Char  **alvec;            /* The (remnants of) alias vector */
  685.  
  686. /*
  687.  * Filename/command name expansion variables
  688.  */
  689. int   gflag;            /* After tglob -> is globbing needed? */
  690.  
  691. #define MAXVARLEN 30        /* Maximum number of char in a variable name */
  692.  
  693. #ifndef MAXPATHLEN
  694. # define MAXPATHLEN 2048
  695. #endif /* MAXPATHLEN */
  696.  
  697. #ifndef MAXNAMLEN
  698. # define MAXNAMLEN 512
  699. #endif /* MAXNAMLEN */
  700.  
  701. /*
  702.  * Variables for filename expansion
  703.  */
  704. extern Char **gargv;        /* Pointer to the (stack) arglist */
  705. extern long gargc;        /* Number args in gargv */
  706.  
  707. /*
  708.  * Variables for command expansion.
  709.  */
  710. extern Char **pargv;        /* Pointer to the argv list space */
  711. extern long pargc;        /* Count of arguments in pargv */
  712. Char   *pargs;            /* Pointer to start current word */
  713. long    pnleft;            /* Number of chars left in pargs */
  714. Char   *pargcp;            /* Current index into pargs */
  715.  
  716. /*
  717.  * History list
  718.  *
  719.  * Each history list entry contains an embedded wordlist
  720.  * from the scanner, a number for the event, and a reference count
  721.  * to aid in discarding old entries.
  722.  *
  723.  * Essentially "invisible" entries are put on the history list
  724.  * when history substitution includes modifiers, and thrown away
  725.  * at the next discarding since their event numbers are very negative.
  726.  */
  727. struct Hist {
  728.     struct wordent Hlex;
  729.     int     Hnum;
  730.     int     Href;
  731.     time_t  Htime;
  732.     Char   *histline;
  733.     struct Hist *Hnext;
  734. }       Histlist;
  735.  
  736. struct wordent paraml;        /* Current lexical word list */
  737. int     eventno;        /* Next events number */
  738. int     lastev;            /* Last event reference (default) */
  739.  
  740. Char    HIST;            /* history invocation character */
  741. Char    HISTSUB;        /* auto-substitute character */
  742.  
  743. /*
  744.  * To print system call errors...
  745.  */
  746. extern char *sys_errlist[];
  747. extern int errno, sys_nerr;
  748.  
  749. #ifdef strerror
  750. # undef strerror
  751. #endif 
  752. #define strerror(e) ((e) < sys_nerr && (e) >= 0 ? sys_errlist[(e)] :\
  753.         "Unknown Error")
  754.  
  755. /*
  756.  * strings.h:
  757.  */
  758. #ifndef SHORT_STRINGS
  759. #define Strchr(a, b)          strchr(a, b)
  760. #define Strrchr(a, b)      strrchr(a, b)
  761. #define Strcat(a, b)          strcat(a, b)
  762. #define Strncat(a, b, c)     strncat(a, b, c)
  763. #define Strcpy(a, b)          strcpy(a, b)
  764. #define Strncpy(a, b, c)     strncpy(a, b, c)
  765. #define Strlen(a)        strlen(a)
  766. #define Strcmp(a, b)        strcmp(a, b)
  767. #define Strncmp(a, b, c)    strncmp(a, b, c)
  768.  
  769. #define Strspl(a, b)        strspl(a, b)
  770. #define Strsave(a)        strsave(a)
  771. #define Strend(a)        strend(a)
  772. #define Strstr(a, b)        strstr(a, b)
  773.  
  774. #define str2short(a)         (a)
  775. #define blk2short(a)         saveblk(a)
  776. #define short2blk(a)         saveblk(a)
  777. #define short2str(a)         strip(a)
  778. #else
  779. #define Strchr(a, b)       s_strchr(a, b)
  780. #define Strrchr(a, b)         s_strrchr(a, b)
  781. #define Strcat(a, b)          s_strcat(a, b)
  782. #define Strncat(a, b, c)     s_strncat(a, b, c)
  783. #define Strcpy(a, b)          s_strcpy(a, b)
  784. #define Strncpy(a, b, c)    s_strncpy(a, b, c)
  785. #define Strlen(a)        s_strlen(a)
  786. #define Strcmp(a, b)        s_strcmp(a, b)
  787. #define Strncmp(a, b, c)    s_strncmp(a, b, c)
  788.  
  789. #define Strspl(a, b)        s_strspl(a, b)
  790. #define Strsave(a)        s_strsave(a)
  791. #define Strend(a)        s_strend(a)
  792. #define Strstr(a, b)        s_strstr(a, b)
  793. #endif 
  794.  
  795. #define    NOSTR    ((Char *) 0)
  796. /*
  797.  * setname is a macro to save space (see sh.err.c)
  798.  */
  799. char   *bname;
  800.  
  801. #define    setname(a)    (bname = (a))
  802.  
  803. #ifdef VFORK
  804. Char   *Vsav;
  805. Char   *Vdp;
  806. Char   *Vexpath;
  807. char  **Vt;
  808.  
  809. #endif /* VFORK */
  810.  
  811. Char  **evalvec;
  812. Char   *evalp;
  813.  
  814. extern struct mesg {
  815.     char   *iname;        /* name from /usr/include */
  816.     char   *pname;        /* print name */
  817. }       mesg[];
  818.  
  819. /* word_chars is set by default to WORD_CHARS but can be overridden by
  820.    the worchars variable--if unset, reverts to WORD_CHARS */
  821.  
  822. Char   *word_chars;
  823.  
  824. #define WORD_CHARS "*?_-.[]~="    /* default chars besides alnums in words */
  825.  
  826. Char   *STR_SHELLPATH;
  827.  
  828. #ifdef _PATH_BSHELL
  829. Char   *STR_BSHELL;
  830. #endif 
  831. Char   *STR_WORD_CHARS;
  832. Char  **STR_environ;
  833.  
  834. #include "tc.h"
  835. #include "sh.decls.h"
  836.  
  837. #endif /* _h_sh */
  838.